
/*=============================================================================
*
*   Copyright (C) 2020 All rights reserved.
*
*   Filename:		test_tensor.cpp
*
*   Author: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Date:  2020-01-17 16:54
*
*   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Last modified:	2020-03-30 22:40
*
*   Description:
*
=============================================================================*/
#define BOOST_AUTO_TEST_MAIN

#include "../include/arithmetic/tensor.hpp"
#include <boost/test/included/unit_test.hpp>
#include <iostream>

using namespace geoxfem;
using namespace geoxfem::arithmetic;

BOOST_AUTO_TEST_CASE(tensor_test) {

  Stress<geometry::plane_stress> t1_2d;
  t1_2d << 80, -60, 0,  //
    -60, -40, 0,        //
    0, 0, 0;
  BOOST_CHECK_CLOSE(t1_2d.Pmax(), 104.8, 1e-1);
  BOOST_CHECK_CLOSE(t1_2d.Pmin(), -64.9, 1e-1);
  ////////////////////////////////
  Stress<geometry::plane_stress> t2_2d;
  t2_2d << 0, 20, 0,  //
    20, -80, 0,       //
    0, 0, 0;
  BOOST_CHECK_CLOSE(t2_2d.Pmax(), 4.721, 1e-1);
  BOOST_CHECK_CLOSE(t2_2d.Pmin(), -84.721, 1e-1);

  t1_2d += t2_2d;
	std::cout << t1_2d << std::endl;
  ////////////////////////////////
  Stress<geometry::three_dimension> t1_3d;

  t1_3d << 5, 0, -5,  //
    0, -5, 0,         //
    -5, 0, 5;
  BOOST_CHECK_CLOSE(t1_3d.I1(), 5, 1e-1);
  BOOST_CHECK_CLOSE(t1_3d.I2(), -50, 1e-1);
  BOOST_CHECK_CLOSE(t1_3d.I3(), 0, 1e-1);
  BOOST_CHECK_CLOSE(t1_3d.Pmax(), 10, 1e-1);
  BOOST_CHECK(approximate(t1_3d.Pmid(), 0));
  BOOST_CHECK_CLOSE(t1_3d.Pmin(), -5, 1e-1);
  BOOST_CHECK_CLOSE(t1_3d.I1() / _real(3), _real(5. / 3.), 1e-1);
  BOOST_CHECK_CLOSE(std::sqrt(t1_3d.J2() * _real(2) / _real(3)),
                    _real(5) / _real(3) * std::sqrt(14), 1e-1);
  ////////////////////////////////
  Stress<geometry::three_dimension> t2_3d;
  t2_3d << 0, -1, 1,  //
    -1, 0, -1,        //
    1, -1, 0;
  BOOST_CHECK_CLOSE(t2_3d.Pmax(), 2, 1e-1);
  BOOST_CHECK_CLOSE(t2_3d.Pmid(), -1, 1e-1);
  BOOST_CHECK_CLOSE(t2_3d.Pmin(), -1, 1e-1);
  BOOST_CHECK_CLOSE(t2_3d.J2(), 3, 1e-1);
  BOOST_CHECK_CLOSE(t2_3d.lode2(), -_real(M_PI / 6.), 1e-1);
  Stress<geometry::three_dimension> t3_3d;
  t3_3d << 7, 3, 0,  //
    3, 7, 4,         //
    0, 4, 7;
  BOOST_CHECK_CLOSE(t3_3d.Pmax(), 12, 1e-1);
  BOOST_CHECK_CLOSE(t3_3d.Pmid(), 7, 1e-1);
  BOOST_CHECK_CLOSE(t3_3d.Pmin(), 2, 1e-1);
  /* //////////////////////////////// */
  Stress<geometry::three_dimension> t4_3d;
  t4_3d << -13, -1, -4,  //
    -1, -13, -4,         //
    -4, -4, -10;
  BOOST_CHECK_CLOSE(t4_3d.Pmax(), -6, 1e-1);
  BOOST_CHECK_CLOSE(t4_3d.Pmid(), -12, 1e-1);
  BOOST_CHECK_CLOSE(t4_3d.Pmin(), -18, 1e-1);
  BOOST_CHECK_CLOSE(t4_3d.lode2(), 0, 1e-1);
  BOOST_CHECK_CLOSE(t4_3d.J2(), 36, 1e-1);
}
